#!/bin/bash

host=$1
remote_folder=$2
tracking_sheet_list=$3

print_usage ()
{
    echo "Usage $0 <host> <remote folder> <tracking sheet list> "
}

if [ "x$remote_folder" = "x" ]; then
    print_usage
    exit 1
fi

if [ ! -f $tracking_sheet_list ]; then
    echo "Tracking sheet list >$comreflist< doesn't exist. Aborting ..."
    exit 1
fi

echo "Starting ... at `date`"

for i in `cat $tracking_sheet_list`
do
  #echo "$i"
  #data=`ssh root@125.215.150.69 "find /data/STORAGE_FOLDER -name "*$i*" -print"`
  data=`ssh root@$1 "find $2 -name "$i" -print"`
  #data= echo $data | sed s/\\\&/\\\\\\\&/g
  #echo $data

  if [ $? -ne 0 ]; then
      echo "Failed to download $data"
  else
      echo "OK"
      #echo scp root@$1:"$data" /home/fredericc/
  fi

done

echo "Ending ... at `date`"
